package com.zhanpple.color_picker.library

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.zhanpple.color_picker.library.databinding.HsvColorPickerBinding

/**
 * @author zmp
 * @date : 2022/4/7 19:51
 * des:HSVPickerGroup
 */
class HSVPickerGroup @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
    private val mViewBinding by lazy {
        HsvColorPickerBinding.inflate(LayoutInflater.from(context), this)
    }

    init {
        mViewBinding.huaPickerView.mColorHueBack = {
            mViewBinding.hsvColorView.setColorHue(it)
        }
        mViewBinding.hsvColorView.mColorBack = {
            mViewBinding.colorProgress.setCurrentColor(it, false, back = true)
        }
        mViewBinding.colorProgress.mColorBack = {
            mViewBinding.colorShowPreView.mColor = it
        }
        //TODO test color
        setResumeColor(Color.parseColor("#AAFF22FF"))
    }

    fun setResumeColor(color: Int) {
        mViewBinding.huaPickerView.setCurrentColor(color, back = false)
        mViewBinding.hsvColorView.setCurrentColor(color, false)
        mViewBinding.colorProgress.setCurrentColor(color, useAlpha = true, back = true)
    }
}